package com.jqing.lib.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;

/**
 * Created by chshqiang on 15-6-18.
 * 自动跳转到底部的ListView
 */
public class SkipToBottomListView extends ListView {
    public SkipToBottomListView(Context context) {
        super(context);
    }

    public SkipToBottomListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SkipToBottomListView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        super.onLayout(changed, l, t, r, b);

        skipToBottom();
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);

        skipToBottom();
    }

    public void skipToBottom() {
        if (2 < getCount())
            setSelection(getCount() - 1);
    }

}
